﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HML.Demo
{
    public partial class NumeralAdjustLabelForm : ItemFormTemplate
    {
        public NumeralAdjustLabelForm()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form_Load);
            this.Shown += new System.EventHandler(this.Form_Shown);
        }

        #region 实现

        public override ItemFormTemplateViewObject AsynchRequestTask(ItemFormTemplateViewObject view)
        {
            System.Threading.Thread.Sleep(300);
            view.ViewData = DemoHelper.GetDescription(AppDomain.CurrentDomain.BaseDirectory + "例子\\控件\\NumeralAdjustLabelForm\\NumeralAdjustLabelForm.rtf");
            return view;
        }

        public override void DataBind(ItemFormTemplateViewObject viewObject)
        {
            this.introduceBrowser.Rtf = viewObject.ViewData.ToString();
        }

        public override void ShowView()
        {
            base.ShowView();
        }

        public override void HideView()
        {
            base.HideView();
        }

        public override void CloseView()
        {
            base.CloseView();
        }

        #endregion

        #region 属性面板

        private void Form_Load(object sender, EventArgs e)
        {
            this.controlContainer.SizeChanged += this.ControlContainer_SizeChanged;

            this.demo_control.RelevancyControl = this.demo_control_numericUpDown;
            this.demo_control.StyleAppearance.Normal.TextColor = Color.White;
            this.demo_control.StyleAppearance.Focused.TextColor = Color.Gold;
            this.demo_control.ChangeInterval = 1;
            this.demo_control.MaxValueProperty = "Maximum";
            this.demo_control.MinValueProperty = "Minimum";
            this.demo_control.ValueProperty = "Value";

            this.textAlign_dropDownListPlus.Multiple = false;
            this.textAlign_dropDownListPlus.BindEnumList<ContentAlignment>(this.demo_control.TextAlignment);
            this.textAlign_dropDownListPlus.SelectedItemsChanged += this.TextAlignment_dropDownListPlus_SelectedItemsChanged;

            this.changeInterval_label.Text = this.demo_control.ChangeInterval.ToString();
            this.changeInterval_trackBarPlus.Value = (float)this.demo_control.ChangeInterval;
            this.changeInterval_trackBarPlus.ValueChanged += this.ChangeInterval_trackBarPlus_ValueChanged; ;

            this.demo_control_numericUpDown_toggleSwitch.IsOn = this.demo_control_numericUpDown.Enabled;
            this.demo_control_numericUpDown_toggleSwitch.Toggled += this.Demo_control_numericUpDown_toggleSwitch_Toggled;

        }

        private void Form_Shown(object sender, EventArgs e)
        {
            this.splitContainer.SplitterDistance = Math.Max(this.splitContainer.Width / 4, this.splitContainer.Width - MainForm.GlobalSplitWidth);
            this.splitContainer.SplitterMoved += this.SplitContainer_SplitterMoved;

            MainForm.LoadAssistTabControl(this.assistTabControl);
        }

        private void SplitContainer_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SplitContainer control = (SplitContainer)sender;
            MainForm.GlobalSplitWidth = this.splitContainer.Width - control.SplitterDistance;
        }

        private void ControlContainer_SizeChanged(object sender, EventArgs e)
        {
            Panel control = (Panel)sender;
            this.demo_control.Location = new Point((control.Width - (this.demo_control.Width + this.demo_control_numericUpDown.Width)) / 2, (control.Height - this.demo_control.Height) / 2);
            this.demo_control_numericUpDown.Location = new Point(this.demo_control.Location.X + this.demo_control.Width, (control.Height - this.demo_control_numericUpDown.Height) / 2);
        }

        private void TextAlignment_dropDownListPlus_SelectedItemsChanged(object sender, EventArgs e)
        {
            DropDownListPlus control = (DropDownListPlus)sender;
            this.demo_control.TextAlignment = (ContentAlignment)control.SelectedItem.Tag;
        }

        private void ChangeInterval_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.ChangeInterval = (decimal)control.Value;
            this.changeInterval_label.Text = this.demo_control.ChangeInterval.ToString();
        }

        private void Demo_control_numericUpDown_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control_numericUpDown.Enabled = control.IsOn;
        }

        #endregion

    }
}
